class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        if(nums.empty()) return {-1,-1};

        int left=0,right=nums.size()-1;
        vector<int> ret;
        while(left<right)
        {
            int mid=left+(right-left)/2;
            if(target<=nums[mid])
            {
                right=mid;
            }
            else
            {
                left=mid+1;
            }
           
        }
        //leftright相遇判断相遇位置是否是结果
        if(nums[left]==target) ret.push_back(left);
        else return {-1,-1};
        
        //寻找右端点
        right=nums.size()-1;
        while(left<right)
        {
            int mid=left+(right-left+1)/2;
            if(target<nums[mid])
            {
                right=mid-1;
            }
            else 
            {
                left=mid;
            }
        }
        ret.push_back(left);
        return ret;
    }
};
